package com.db;

import java.sql.*;

public class DB {
    private static final String URL = "jdbc:mysql://192.168.1.29:3306/wechat?user=admin&password=Zhang@123456";
    private Connection conn;



    // 静态块
    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(URL);
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConn() {
        return conn;
    }


    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        // Class.forName("com.mysql.cj.jdbc.Driver");
        // Connection conn = DriverManager.getConnection(URL);
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("select * from users");
        while (rs.next()) {
            System.out.println(rs.getString("uname"));
        }
    }

}
